//
//  TopBannerView.m
//  Contacts
//
//  Created by 李 雷川 on 14-7-15.
//  Copyright (c) 2014年 李 雷川. All rights reserved.
//

#import "TopBannerView.h"

@implementation TopBannerView
@synthesize bannerView,headView,nameLabel,switchHeadBtn,userCenterBlock;
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        bannerView = [[UIImageView alloc]initWithFrame:self.bounds];
        bannerView.image = [UIImage imageNamed:@"top_banner.png"];
        [self addSubview:bannerView];
        
        float leftSpace = 20;
        float bottomSpace =10;
        float viewSpace = 10;
        
        nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(leftSpace,CGRectGetHeight(self.frame) - bottomSpace -10, 64,10)];
        nameLabel.text = @"宝义同志";
        nameLabel.textAlignment = NSTextAlignmentCenter;
        nameLabel.backgroundColor = [UIColor clearColor];
        nameLabel.textColor = [UIColor whiteColor];
        nameLabel.font = [UIFont systemFontOfSize:10];
        [self addSubview:nameLabel];
        
        UIImage *headImage = [UIImage imageNamed:@"logo.png"];
        headView = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMidX(nameLabel.frame) - 32,CGRectGetMinY(nameLabel.frame) - viewSpace -64,64,64)];
        headView.image = headImage;
        
        [headView setContentMode:UIViewContentModeScaleAspectFill];
        [headView setClipsToBounds:YES];
        [headView.layer setBorderColor:[UIColor colorWithRed:255 green:255 blue:255 alpha:0.7].CGColor];
        [headView.layer setBorderWidth:2.0];
        [headView.layer setCornerRadius:headView.frame.size.width/2.0];
        [self addSubview:headView];
        
        switchHeadBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        switchHeadBtn.frame = headView.frame;
        [switchHeadBtn addTarget:self action:@selector(enterUserCenter:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:switchHeadBtn];
    }
    return self;
}

-(void)enterUserCenter:(id)sender{
    if (self.userCenterBlock) {
        self.userCenterBlock();
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
